<!--
  - ViewAsh.php
  - v1.3
  - 4/02/2011
  -->

<!--
  - Code Specifications:
  - This code gathers the inputs for ash content, which can only be viewed by
  - the analyst. After inputting values, the results are forwarded to
  - ControllerAsh.php for values computation and database updating.
  -->
	
<?php
	//Gets required libraries
	require '../libraries/UserLibrary.php';
	
	//Formally starts session
	session_start();
	
	//Ensures that the analyst is logged in.
	isSessionSet("analyst", null, "../Logout.php");

	//Gathers the CASL Year and number ans stores it in a session variable
	if(isset($_GET["year"]) && isset($_GET["no"])){
		$_SESSION["year"] = $_GET["year"];
		$_SESSION["no"] = $_GET["no"];
	}
?>

<!-- HTML markup -->
<html>
	<head>
		<title>Ash Content</title>
		<script type="text/javascript" src="../scripts/validateParameterInput.js"></script>
		<link rel="stylesheet" type="text/css" href="../scripts/page.css" />
		<link href="../tools/favicon.ico" rel="shortcut icon" type="image/x-icon" /> 
	</head>
	<body>
		<div id="header"></div>
		<div id="wrapper">
			<div id="pagetop">
				<div class="greeting">Hi, <?php echo $_SESSION["analyst"];?> | <a href="../Logout.php">Log out</a> | <a href="../AnalystHomepage.php"> Home </a></div>
				<div class="homepage"><?php echo $_SESSION["analyst"];?></div>
			</div>
			<form name = "ash" action = "ControllerAsh.php" method = "post">
				<h3>Ash Content</h3>
				<hr/>
				<h4>CASL No: <?php printf("%d-%04d", $_SESSION["year"], $_SESSION["no"]); ?></h4>
				<table>
					<?php
						$connect = mysql_connect("localhost","editanalysis","editanalysis");	
						if (!$connect) {
							die('Could not connect: ' . mysql_error());
						}
						mysql_select_db("casl", $connect);			
					?>
					<tr>
						<td>Weight of the dish(g)</td>
						<td><input type = "text" name = "14/1" id = "14/1" onKeyUp="validDecimal(this)" value = "<?php
								$result = mysql_query("SELECT * FROM edit_analysis  WHERE casl_year = $_SESSION[year] AND 
								casl_sample =  $_SESSION[no] AND parameter_id = 14 ");
								$row = mysql_fetch_array($result);
								echo $row['value1'];
							?>"/></td>
						<td><div id = "error1a" class="error"></div></td>
						<td><input type = "text" name = "14/2" id = "14/2" onKeyUp="validDecimal(this)" value = "<?php
								echo $row['value2'];
							?>"/></td>
						<td><div id = "error1b" class="error"></div></td>
					</tr>
					<tr>
						<td>Weight of the sample(g)</td>
						<td><input type = "text" name = "15/1" id = "15/1" onKeyUp="validDecimal(this)" value = "<?php
								$result = mysql_query("SELECT * FROM edit_analysis  WHERE casl_year = $_SESSION[year] AND 
								casl_sample =  $_SESSION[no] AND parameter_id = 15 ");
								$row = mysql_fetch_array($result);
								echo $row['value1'];
							?>"/></td>
						<td><div id = "error2a" class="error"/></div></td>
						<td><input type = "text" name = "15/2" id = "15/2" onKeyUp="validDecimal(this)" value = "<?php
								echo $row['value2'];
							?>"/></td>
						<td><div id = "error2b" class="error"/></div></td>
					</tr>
					<tr>
						<td>Weight of the dish plus ashed sample(g)</td>
						<td><input type = "text" name = "16/1" id = "16/1" onKeyUp="validDecimal(this)" value = "<?php
								$result = mysql_query("SELECT * FROM edit_analysis  WHERE casl_year = $_SESSION[year] AND 
								casl_sample =  $_SESSION[no] AND parameter_id = 16 ");
								$row = mysql_fetch_array($result);
								echo $row['value1'];
							?>"/></td>
						<td><div id = "error3a" class="error"/></div></td>
						<td><input type = "text" name = "16/2" id = "16/2" onKeyUp="validDecimal(this)" value = "<?php
								echo $row['value2'];
							?>"/></td>
						<td><div id = "error3b" class="error"/></div></td>
					</tr>
					<tr>
						<td></td>
						<td><input type = "submit" name = "compute1" id = "compute1" value = "Compute" onclick = "return checkEmpty('14/1', '15/1', '16/1')"/></td>
						<td></td>
						<td><input type = "submit" name = "compute2" id = "compute2" value = "Compute" onclick = "return checkEmpty('14/2', '15/2', '16/2')"/></td>
						<td></td>
					</tr>
					<tr>
						<td>% Ash:</td>
						<td><div id = "result1"><?php 
								$result = mysql_query("SELECT * FROM analysis_result  WHERE casl_year = $_SESSION[year] AND 
								casl_sample =  $_SESSION[no] ");
								$row = mysql_fetch_array($result);
								echo $row['result_value1'];
							?>
						</div></td>
						<td></td>
						<td><div id = "result2"><?php
								echo $row['result_value2'];
							?>
						</div></td>
					</tr>
					<tr>
						<td>Mean</td>
						<td><div id = "mean"><?php echo $row['mean'];?></div></td>
					</tr>
					<tr>
						<td>Standard Deviation</td>
						<td><div id = "standardDev"><?php echo $row['standard_deviation']?></div></td>
					</tr>
				</table>
				<div id="buttons">
					<input type = "submit" name = "computeBoth" id = "computeBoth" value = "Compute Both" onclick = "return checkEmpty('4/1', '5/1', '6/1')"/>
					<input type="button" value="Back" onClick='document.location.href = "../AnalystHomepage.php"'>			
				</div>			
			</form>
			<div id="footerwrap">
				<div id="footer"> 
					<div class="copyright">Copyright 2011.<a>CASL BIOTECH-UPLB.</a> All Rights Reserved.<br/>
							Arianne Buse&ntilde;os | Darlene Joy Masong | Rick Jason Obrero | Jonathan Pandi | Jonathan Simbahan | Emmanuel Soriano 
					</div> 
	    	    </div>
			</div>				
		</div>			
	</body>
</html>
<?php
	mysql_close($connect);
?>